package 数据结构.堆;

import org.junit.Test;
import 数据结构.堆.数组堆.最大堆.MaxHeap;

import java.util.Random;

/**
 * @author Veng Su 1344114844@qq.com
 * @date 2018/7/25 17:34
 */
public class Main {
    @Test
    public void test(){
        int n=1000000;
        MaxHeap<Integer> maxHeap=new MaxHeap<>();
        Random random=new Random();
        for (int i = 0; i < n; i++) {
            maxHeap.add(random.nextInt(Integer.MAX_VALUE));
        }
        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=maxHeap.extractMax();
        }
        for (int i = 1; i < n; i++) {
            if (arr[i-1]<arr[i]){
                throw new IllegalArgumentException("error");
            }
        }
        System.out.println("sucess");

    }
    @Test
    public void test1(){
        long startTime=System.nanoTime();
        int n=1000000;
        MaxHeap<Integer> maxHeap=new MaxHeap<>();
        Random random=new Random();
        Integer[] arr=new Integer[n];
        for (int i = 0; i < n; i++) {
            arr[i]=random.nextInt(Integer.MAX_VALUE);
        }
        maxHeap.heapify(arr);
        long endTime=System.nanoTime();
        System.out.println(endTime-startTime);

    }
}
